<?php

namespace App\Exports;

use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithColumnWidths;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Events\AfterSheet;

class FixedExport implements FromCollection, WithHeadings, WithColumnWidths, WithEvents
{
    protected $data;

    public function __construct(Collection $data)
    {
        $this->data = $data;
    }

    public function collection()
    {
        return $this->data;
    }

    public function headings(): array
    {
        return [
            '资产编码',
            '资产名称',
            '资产类别',
            '规格',
            '品牌/型号',
            '单位',
            '颜色',
            '购置日期',
            '供应商',
            '保修周期',
            '入账日期',
            '使用年限',
            '原值',
            '残值率',
            '预计残值',
            '到期日',
            '折旧月数',
            '月折旧',
            '已提月份',
            '累计折旧',
            '资产净值',
            '资产状态',
            '领用日期',
            '所属部门',
            '领用人员',
            '存放地点',
            '备注',
        ];

    }

    public function columnWidths(): array
    {
        // 设置每列的宽度
        return [
            'A' => 20,
            'B' => 20,
            'C' => 20,
            'D' => 20,
            'E' => 20,
            'F' => 20,
            'J' => 20,
            'K' => 20,
            'L' => 20,
            'M' => 20,
            // 根据你的需求设置其他列的宽度
        ];
    }

    public function registerEvents(): array
    {
        return [
            AfterSheet::class => function(AfterSheet $event) {
                $event->sheet->getDelegate()->freezePane('A2');
            },
        ];
    }

}